#include<iostream>
#include"contacts.pb.h"

int main()
{
    std::string pro_str;
    
    //将联系人信息序列化并打印结果
    {
        contacts::PersonInfo person;
        person.set_age(20);
        person.set_name("张三");

        if(!person.SerializeToString(&pro_str)){
            std::cerr << "序列化失败！" << std::endl;
            return -1;  
        }
        std::cout << pro_str << std::endl;
    }

    //将序列化结果反序列化并打印
    {
        contacts::PersonInfo person;
        if(!person.ParseFromString(pro_str)){
            std::cerr << "反序列化失败" << std::endl;
            return -1;
        }
        std::cout << "序列化成功" << std::endl 
                  << person.age() << std::endl
                  << person.name() << std::endl;
    }

    return 0;
}